package cn.edu.gcu.lost.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.edu.gcu.lost.dao.MessageMapper;
import cn.edu.gcu.lost.entity.Message;

/**
 * @Description:message服务层
 * @Date:2018-01-25 10:44:42
 */
@Service
@Transactional(readOnly = true)
public class MessageService {

    @Autowired
    private MessageMapper messageMapper;

    public List<Message> findList(String type, String thing, String self, String selfId, String status, String search,
                                  int start, int size) {
        return messageMapper.findList(type, thing, self, selfId, status, search, start, size);
    }

    public Message findDetail(String id) {
        return messageMapper.selectByPrimaryKey(id);
    }

    @Transactional(readOnly = false)
    public boolean save(Message message) {
        if (messageMapper.insert(message) > 0) {
            return true;
        } else {
            return false;
        }
    }


    @Transactional(readOnly = false)
    public Boolean updateStatusByid(String id) {
        if (messageMapper.updateStatusByid(id) > 0) {
            return true;
        }

        return false;

    }

	
	public Integer countNum(String type, String thing, String self, String selfId, String status, String search) {
		return messageMapper.countNum(type,thing,self,selfId,status,search);
	}
	
    @Transactional(readOnly = false)
    public Boolean deleteById(String id) {
        if (messageMapper.deleteByPrimaryKey(id) > 0) {
            return true;
        }
        return false;
    }


    @Transactional(readOnly = false)
    public String deleteMore(String ids) {
        int count = 0;
        int number = 0;
        String operation = null;
        String[] idList = ids.split(";");
        for (String id : idList) {
            if (messageMapper.deleteByPrimaryKey(id) > 0) {
                count++;
            }
            number++;
        }
        if (number == count) {
            operation = "sucess";
        } else if (count != 0) {
            operation = "partial operation faild";
        } else if (count == 0) {
            operation = "all operation faild";
        }
        return operation;

    }

	public List<Message> findListWithAllField(String type, String thing, String status, String search, int start,
			int size) {
        return messageMapper.findListWithAllField(type, thing,status, search, start, size);
	}

	public Message findDetailWithAllField(String id) {
        return messageMapper.findDetailWithAllField(id);
	}


}
